/**
 * Copyright 2016-2018 mobaas.com
 */
package com.mobaas.devops.schedule.job;

import java.util.List;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

import com.mobaas.devops.ComponentFactory;
import com.mobaas.devops.VcsProvider;
import com.mobaas.devops.model.VcsDayStat;
import com.mobaas.devops.service.VcsStatService;

/**
 * 
 * @author billy zhang
 * 
 */
public class VcsDayStatJob extends AbstractJob {

    private static final Logger logger = LoggerFactory.getLogger(VcsDayStatJob.class);

    @Autowired
    private ComponentFactory<VcsProvider> providerFactory;

    @Autowired
    private VcsStatService vcsService;
    
    @Override
	protected void doExecute(Map<String, Object> jobData) {
		logger.info("开始VCS代码提交日统计...");
		
		String name = (String)jobData.get("name");
		VcsProvider provider = providerFactory.getComponent(name);
		provider.init(jobData);
		
	    	List<VcsDayStat> list = provider.getLastDayStatList();
	    	if (list != null && list.size() > 0) {
	    		vcsService.insertDayStat(list);
	    	}
	}
	
}
